﻿package com.petermacko.utils {
	public class DateUtil
	{
		//Returns a two digit representation of the year represented by the specified date.
		public static function getShortYear(d:Date):String {
			var ds:String = String(d.getFullYear());
			if(ds.length<3)	{
				return ds;
			}
			return (ds.substr(ds.length-2));
		}

		//Compares two dates and returns an integer depending on their relationship.	
		public static function compareDates(d1:Date,d2:Date):int {
			var d1ms:Number = d1.getTime();
			var d2ms:Number = d2.getTime();
			if(d1ms>d2ms)	{
				return -1;
			} else if(d1ms<d2ms) {
				return 1;
			} else {
				return 0;
			}
		}

		//Returns a short hour (0 - 12) represented by the specified date.
		public static function getShortHour(d:Date):int {
			var h:int = d.hours;
			if(h==0||h==12) {
				return 12;
			} else if(h>12) {
				return h-12;
			} else {
				return h;
			}
		}

		//Returns a string indicating whether the date represents a time in the ante meridiem (AM) or post meridiem (PM).
		public static function getAMPM(d:Date):String {
			return (d.hours>11)?"PM":"AM";
		}
	}
}
